
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_STUDERENDE_FAG_EBAS_KARAKTER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_STUDERENDE_FAG] DROP CONSTRAINT FK_EBAS_STUDERENDE_FAG_EBAS_KARAKTER
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_KARAKTER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_KARAKTER]
GO

CREATE TABLE [dbo].[EBAS_KARAKTER] (
	[GUID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[KARAKTER] [varchar] (50) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[KARAKTER_SKALA_GUID] [uniqueidentifier] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_KARAKTER] WITH NOCHECK ADD 
	CONSTRAINT [PK_EBAS_KARAKTER] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

CREATE  UNIQUE  INDEX [IDX_EBAS_KARAKTER_KARAKTER_KARAKTER_SKALA_GUID] ON [dbo].[EBAS_KARAKTER]([KARAKTER], [KARAKTER_SKALA_GUID]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_KARAKTER] ADD 
	CONSTRAINT [FK_EBAS_KARAKTER_EBAS_KARAKTER_SKALA] FOREIGN KEY 
	(
		[KARAKTER_SKALA_GUID]
	) REFERENCES [dbo].[EBAS_KARAKTER_SKALA] (
		[GUID]
	)
GO

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '00', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '03', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '5', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '6', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '7', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '8', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '9', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '10', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '11', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '13', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '13-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'A+', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'A', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'A-', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'B+', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'B', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'B-', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'C+', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'C', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'C-', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'D+', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'D', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'D-', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'E', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'E-', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), 'F', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = 'US-skala'	

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '-3', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '00', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'	

INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '02', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'
	
INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '4', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'	
	
INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '7', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'	
	
INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '10', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'
	
INSERT INTO EBAS_KARAKTER (GUID, KARAKTER, KARAKTER_SKALA_GUID) 
	SELECT NEWID(), '12', S.GUID
	FROM EBAS_KARAKTER_SKALA S
	WHERE S.NAVN = '7-skala'	
GO